<template>
	<view>
		<view class="main">
			<view class="user">
				<image class="tx" :src="userInfo.avatar"></image>
				<view class="name">
					{{userInfo.nickname}}
				</view>
			</view>
			<view class="tips">
				<view class="tips-item" v-for="(item,index) in userInfo.biaoqian">
					{{item}}
				</view>
			</view>
		</view>
		<u-gap height="10rpx" bgColor="#F7F7F7"></u-gap>
		<view class="main">
			<view class="status-wrap">
				<view class="label" v-if="userInfo.yq_stu==2 && userInfo.yq_type==2">
					已同意
				</view>
				<view class="label" v-if="userInfo.yq_stu==1 && userInfo.yq_type==2">
					被邀请
				</view>
				<view class="label" v-if="userInfo.yq_stu==1 && userInfo.yq_type==1">
					邀请中
				</view>
				<view class="btns">
					<view class="phone" v-if="userInfo.yq_stu==2">
						手机号：{{userInfo.mobile}}
					</view>
					<view class="btn" v-if="userInfo.yq_stu==2" @click="copy">
						复制
					</view>
					<view class="btn no" v-if="userInfo.yq_type==2 && userInfo.yq_stu==1" @click="applyUser(2)">
						拒绝
					</view>
					<view class="btn" v-if="userInfo.yq_type==2 && userInfo.yq_stu==1" @click="applyUser(1)">
						同意
					</view>
				</view>
			</view>
		</view>
		<u-gap height="10rpx" bgColor="#F7F7F7"></u-gap>
		<view class="main">
			<view class="title">
				留言板
			</view>
			<view class="lists" v-for="(item,index) in lists">
				<image class="tx" :src="item.avatar"></image>
				<view class="user-msg">
					<view class="names">
						<view class="name">
							{{item.nickname}}
						</view>
						<view class="time">
							{{item.createtime}}
						</view>
					</view>
					<view class="content">
						{{item.content}}
					</view>
				</view>
			</view>
		</view>

		<view class="submit-tc">
		</view>
		<view class="submit flexAJC" @click="sendMsg">
			留言
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lists: [],
				uid: '',
				userInfo: {}
			};
		},
		onLoad(o) {
			this.uid = o.uid
			this.getDetail()
			this.getList()
		},
		methods: {
			copy(){
				uni.setClipboardData({
					data:this.userInfo.mobile
				})
			},
			applyUser(e) {
				this.$api.user.yq_cz({
					uid: this.uid,
					type: e
				}).then(res => {
					if(e==2){
						uni.navigateBack()
					}else{
						this.getDetail()
					}
				})
			},
			getList() {
				this.$api.user.yq_ly({
					uid: this.uid
				}).then(res => {
					this.lists = res.data.liuyan
				})
			},
			sendMsg() {
				uni.showModal({
					title: '提示',
					placeholderText: '请输入留言内容',
					editable: true,
					success: (res) => {
						if (res.confirm) {
							if (uni.$u.test.isEmpty(res.content)) {
								uni.showToast({
									title: "留言内容不能为空",
									icon: "none"
								})
								return false
							}
							this.$api.user.yq_send({
								uid: this.uid,
								content: res.content
							}).then(res => {
								uni.showToast({
									title: "留言成功",
								})
								this.getList()
							})
						}
					}
				});

			},
			getDetail() {
				this.$api.user.yq_detail({
					uid: this.uid
				}).then(res => {
					this.userInfo = res.data.user
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.tips {
		overflow: hidden;
		width: 100%;

		.tips-item {
			float: left;
			margin-right: 60rpx;
			width: auto;
			height: 70rpx;
			background: #FBFAF6;
			border-radius: 35rpx;
			border: 1px solid #F4BD38;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 22rpx;
			color: #F4BD38;
			padding: 0 28rpx;
			margin-bottom: 28rpx;
		}
	}

	.main {
		padding: 40rpx 32rpx;
		width: 100%;

		.user {
			display: flex;
			align-items: center;
			margin-bottom: 40rpx;

			.tx {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				margin-right: 36rpx;
			}

			.name {
				font-size: 28rpx;
				color: #1F1F1F;
				font-weight: bold;
			}
		}

		.status-wrap {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.label {
				font-size: 32rpx;
				font-weight: bold;
			}

			.btns {
				display: flex;
				align-items: center;

				.phone {
					color: #656565;
					font-size: 28rpx;
				}

				.btn {
					width: 121rpx;
					height: 69rpx;
					background: #FBFAF6;
					border-radius: 34rpx;
					border: 1px solid #F4BD38;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #F4BD38;
					font-size: 28rpx;
					margin-left: 36rpx;

					&.no {
						background: #FBFAF6;
						border: 1px solid #B8B8B8;
						color: #656565;
					}
				}
			}
		}

		.title {
			font-size: 32rpx;
			font-weight: bold;
			margin-bottom: 28rpx;
		}

		.lists {
			width: 100%;
			display: flex;
			margin-bottom: 50rpx;

			.tx {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
			}

			.user-msg {
				width: calc(100% - 120rpx);
				padding-left: 26rpx;

				.names {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 38rpx;

					.name {
						font-size: 28rpx;
						font-weight: bold;
					}

					.time {
						color: #505050;
						font-size: 26rpx;
					}

				}

				.content {
					font-size: 28rpx;
					color: #505050;
					line-height: 48rpx;
				}
			}
		}
	}

	.submit-tc {
		height: 200rpx;
	}

	.submit {
		width: 500rpx;
		height: 110rpx;
		background: #F4BD38;
		border-radius: 55rpx;
		color: #FFFFFF;
		font-weight: bold;
		font-size: 26rpx;
		position: fixed;
		bottom: 70rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>